// pages/videoResult/index.js
const api = require('./../../config/api')
const request = require('./../../utils/request')
const { stringify } = require('./../../utils/util')
Page({
  /**
   * 页面的初始数据
   */
  data: {
    videoResultList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    const patientInfo = wx.getStorageSync('patientInfo')
    const userId = wx.getStorageSync('userId')
    const data = {
      userId: userId,
      patientId: patientInfo.id,
    }
    this.getVideoResultList(data)
  },
  // 获取评估结果
  getVideoResultList: async function (data) {
    const res = await request.get(api.getVideoResultList, data)
    if (res.httpStatus === 200) {
      for (let i = 0; i < res.data.length; i += 1) {
        res.data[i].createTime = res.data[i].createTime.substring(0, 10)
      }
      this.setData({
        videoResultList: res.data,
      })
    }
  },
  videoDetail(val) {
    wx.navigateTo({
      url: `/pages/videoDetail/index?item=${stringify(
        val.currentTarget.dataset.item
      )}`,
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
})
